<template>
	<view>
		<view class="uni-container" style="float: left;">
            <span>设置每日签到金币奖励</span>
			<uni-forms ref="form" validateTrigger="bind">
				<uni-forms-item label="8点" name="title" labelWidth="50">
					<input class="uni-input-border" type="text" v-model="todayqiandao.sign1" style="width: 200px;"/>
				</uni-forms-item>
                <uni-forms-item label="12点" name="title" labelWidth="50">
                	<input class="uni-input-border" type="text" v-model="todayqiandao.sign2" style="width: 200px;"/>
                </uni-forms-item>
                <uni-forms-item label="16点" name="title" labelWidth="50">
                	<input class="uni-input-border" type="text" v-model="todayqiandao.sign3" style="width: 200px;"/>
                </uni-forms-item>
                <uni-forms-item label="20点" name="title" labelWidth="50">
                	<input class="uni-input-border" type="text" v-model="todayqiandao.sign4" style="width: 200px;"/>
                </uni-forms-item>
                <uni-forms-item label="22点" name="title" labelWidth="50">
                	<input class="uni-input-border" type="text" v-model="todayqiandao.sign5" style="width: 200px;"/>
                </uni-forms-item>
				<view class="uni-button-group pointer">
					<button class="uni-button uni-button-full" type="primary" :disabled="isLoading" @click="save">保存</button>
				</view>
			</uni-forms>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isLoading:false,
				"todayqiandao":{
					"sign1": 0,
					"sign2": 0,
					"sign3": 0,
					"sign4": 0,
					"sign5": 0,
				}
			}
		},
		mounted() {
			this.getinfo()
		},
		methods: {
			getinfo(){
				this.isLoading = true
				uni.showLoading({
					title: '加载中'
				});
				uniCloud.callFunction({
					name: 'uni-admin',
					data: {
						action: "admin/loadconfig",
						data: {
							id: 'todayqiandao'
						}
					}
				}).then((res) => {
					console.log(res, "get--------------")
					this.todayqiandao = res.result.config
					uni.hideLoading();
				}).catch((res) => {
					console.log(res)
				}).finally(err => {
					this.isLoading = false
					uni.hideLoading();
				})
			},
			save(){
				this.isLoading = true
				delete this.todayqiandao._id;
				for(let key in this.todayqiandao){
					if(key != '_id'){
						this.todayqiandao[key] = Number(this.todayqiandao[key])
					}
				}
				console.log(this.todayqiandao)
				uni.showLoading({
					title: '保存中'
				});
				uniCloud.callFunction({
					name: 'uni-admin',
					data: {
						action: "admin/setconfig",
						data: {
							json: JSON.stringify({
								todayqiandao: this.todayqiandao
							})
						}
					}
				}).then((res) => {
					console.log(res, "save-------------")
					this.isLoading = false
					uni.hideLoading();
					uni.showToast({
						title: "修改成功",
						icon: 'none',
						duration: 2000
					})
				}).catch((res) => {
					console.log(res)
				}).finally(err => {
					this.isLoading = false
					uni.hideLoading();
				})
			}
		}
	}
</script>

<style>

</style>
